package com.ruoyi.wuyi.service.impl;

import com.ruoyi.common.core.domain.model.LoginUser;
import com.ruoyi.common.utils.DateUtils;
import com.ruoyi.common.utils.SecurityUtils;
import com.ruoyi.common.utils.uuid.UUID;
import com.ruoyi.wuyi.domain.XiaoshouInfo;
import com.ruoyi.wuyi.mapper.XiaoshouInfoMapper;
import com.ruoyi.wuyi.service.IXiaoshouInfoService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.HashMap;
import java.util.List;

/**
 * 售卖信息Service业务层处理
 * 
 * @author ruoyi
 * @date 2021-07-06
 */
@Service
public class XiaoshouInfoServiceImpl implements IXiaoshouInfoService 
{
    @Autowired
    private XiaoshouInfoMapper xiaoshouInfoMapper;


    /**
     * 查询售卖信息
     * 
     * @param id 售卖信息ID
     * @return 售卖信息
     */
    @Override
    public XiaoshouInfo selectXiaoshouInfoById(String id)
    {
        XiaoshouInfo xiaoshouInfo = xiaoshouInfoMapper.selectXiaoshouInfoById(id);
        xiaoshouInfo.setViewNum(xiaoshouInfo.getViewNum()+1);
        xiaoshouInfoMapper.updateXiaoshouInfo(xiaoshouInfo);
        return xiaoshouInfoMapper.selectXiaoshouInfoById(id);
    }

    /**
     * 查询售卖信息列表
     * 
     * @param xiaoshouInfo 售卖信息
     * @return 售卖信息
     */
    @Override
    public List<XiaoshouInfo> selectXiaoshouInfoList(XiaoshouInfo xiaoshouInfo)
    {
        return xiaoshouInfoMapper.selectXiaoshouInfoList(xiaoshouInfo);
    }
    @Override
    public List<XiaoshouInfo> selectSellList(XiaoshouInfo xiaoshouInfo)
    {
        return xiaoshouInfoMapper.selectSellList(xiaoshouInfo);
    }
    @Override
    public List<HashMap<String, Object>> selectCount() {
        return xiaoshouInfoMapper.selectCount();
    }

    /**
     * 新增售卖信息
     * 
     * @param xiaoshouInfo 售卖信息
     * @return 结果
     */
    @Override
    public int insertXiaoshouInfo(XiaoshouInfo xiaoshouInfo)
    {
        LoginUser loginUser = SecurityUtils.getLoginUser();
        Long userId = loginUser.getUser().getUserId();
        xiaoshouInfo.setCreateBy(userId+"");
        xiaoshouInfo.setId(UUID.randomUUID().toString().replaceAll("-",""));
        Date date = new Date();
        xiaoshouInfo.setSellTime(date);
        xiaoshouInfo.setCreateTime(date);
        //新增数据未审核
        xiaoshouInfo.setIsCheck("0");
        //新增数据上架
        xiaoshouInfo.setIsShop("1");
        return xiaoshouInfoMapper.insertXiaoshouInfo(xiaoshouInfo);
    }

    /**
     * 修改售卖信息
     * 
     * @param xiaoshouInfo 售卖信息
     * @return 结果
     */
    @Override
    public int updateXiaoshouInfo(XiaoshouInfo xiaoshouInfo)
    {
        xiaoshouInfo.setUpdateTime(DateUtils.getNowDate());
        return xiaoshouInfoMapper.updateXiaoshouInfo(xiaoshouInfo);
    }

    /**
     * 批量删除售卖信息
     * 
     * @param ids 需要删除的售卖信息ID
     * @return 结果
     */
    @Override
    public int deleteXiaoshouInfoByIds(String[] ids)
    {
        return xiaoshouInfoMapper.deleteXiaoshouInfoByIds(ids);
    }

    /**
     * 删除售卖信息信息
     * 
     * @param id 售卖信息ID
     * @return 结果
     */
    @Override
    public int deleteXiaoshouInfoById(String id)
    {
        return xiaoshouInfoMapper.deleteXiaoshouInfoById(id);
    }


    @Override
    public List<XiaoshouInfo> selectListByType(String createBy) {
        return xiaoshouInfoMapper.selectListByType(createBy);
    }

    @Override
    public List<XiaoshouInfo> getAroundGoods(String longitude, String latitude, String distance, String keyWords ,String[] sellNums  ) {
        return xiaoshouInfoMapper.getAroundGoods(longitude,latitude,distance,keyWords,sellNums);
    }

    @Override
    public List<HashMap<String,Object>> countBarSellByType() {
        return xiaoshouInfoMapper.countBarSellByType();
    }

    @Override
    public HashMap<String, Integer> countSellNum() {
        return xiaoshouInfoMapper.countSellNum();
    }

    @Override
    public List<HashMap<String, Object>> countLineBySell() {
        return xiaoshouInfoMapper.countLineBySell();
    }

    @Override
    public List<HashMap<String, Object>> hotSellSort() {
        return xiaoshouInfoMapper.hotSellSort();
    }

    @Override
    public List<HashMap<String, Object>> viewNumSort() {
        return xiaoshouInfoMapper.viewNumSort();
    }

    @Override
    public List<XiaoshouInfo> getAroundPlays(String longitude, String latitude, String distance, String keyWords) {
        return xiaoshouInfoMapper.getAroundPlays(longitude,latitude,distance,keyWords);
    }

}
